<?php
namespace Admin\Controller;
use Think\Controller;
use Admin\Event\UserEvent;
class SystemController extends AdminController {
    public function info(){
        $this->assign('title','商店设置');
        $res = M('system')->find();
//        dump($res);die;
        $this->assign('res',$res);
        $this->display('System/info');
    }
    public function infoedit(){
        if(IS_POST){
            $data['name']=$_POST['name'];
            $data['tel']=$_POST['tel'];
            $data['email']=$_POST['email'];
            $data['address'] = $_POST['address'];
            if(M('system')->where("id=1")->save($data)){
                $this->success('修改成功',U('System/info'));
            }else{
                $this->error('修改失败',U('System/info'));
            }


        }else{
            E('非法');
        }

    }
    public function pay(){
        $this->assign('title','支付设置');
        $res = M('pay')->select();
        $this->assign('res',$res);
        $this->display('System/pay');
    }
    public function payedit(){
        $this->display('System/payedit');
    }
    public function payeditdo(){
        $data['name']=$_POST['name'];
        $data['is_open']=$_POST['is_open'];
        $data['create_time']=date('Y-m-d H:i:s');
        $res = M('pay')->add($data);
        if($res){
            $this->success('新增成功',U('System/pay'));
        }else{
            $this->error('新增失败',U('System/payedit'));
        }
    }

        public function express(){
        $this->assign('title','快递设置');
        $res = M('deliver')->select();
        $this->assign('res',$res);
        $this->display('System/express');
    }
    public function expressedit(){
        $this->display('System/expressedit');
    }
    public function expresseditdo(){
        $data['name']=$_POST['name'];
        $data['is_open']=$_POST['is_open'];
        $data['create_time']=date('Y-m-d H:i:s');
        $res = M('deliver')->add($data);
        if($res){
            $this->success('新增成功',U('System/express'));
        }else{
            $this->error('新增失败',U('System/expressedit'));
        }
    }
    public function is_open_pay(){
        $ms = M("pay"); // 实例化User对象
        $b = I('get.sub')==0?'1':'0';
        $data['is_open'] = $b;
        $id = I('get.id',0,'int');//id
        $res = $ms->where("id='$id'")->save($data);
        header("Location:".$_SERVER['HTTP_REFERER']);//改变后返回
    }

    public function is_open_express(){
        $ms = M("deliver"); // 实例化User对象
        $b = I('get.sub')==0?'1':'0';
        $data['is_open'] = $b;
        $id = I('get.id',0,'int');//id
        $res = $ms->where("id='$id'")->save($data);
        header("Location:".$_SERVER['HTTP_REFERER']);//改变后返回

    }
    public function pay_del(){
        if(IS_GET){
            $id = I('get.id',0,'int');
            M('pay')->delete($id);
            header("Location:".$_SERVER['HTTP_REFERER']);//改变后返回
        }else{
            E('非法访问');
        }
    }
    public function express_del(){
        if(IS_GET){
            $id = I('get.id',0,'int');
            M('deliver')->delete($id);
            header("Location:".$_SERVER['HTTP_REFERER']);//改变后返回
        }else{
            E('非法访问');
        }
    }





    }